#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- Python -*-

"""
 @file ${idlFileParam.idlFileNoExt}_idl_example.py
 @brief Python example implementations generated from ${idlFileParam.idlFile}
#set( $Date$ = "dummy" )
 @date \$Date$

#if( ${rtcParam.docCreator.length()} > 0 )
 @author ${tmpltHelperPy.convertAuthorDocPy(${rtcParam.docCreator})}
#end
#if( ${rtcParam.docLicense.length()} > 0 )

 ${tmpltHelperPy.convertDocPy(${rtcParam.docLicense})}
#end

"""

import omniORB
from omniORB import CORBA, PortableServer
${pyConv.convModuleName(${idlFileParam})}

#foreach($serviceClassParam in ${idlFileParam.serviceClassParams})

class ${tmpltHelper.getBasename(${serviceClassParam.name})}_i (${pyConv.getModuleName(${serviceClassParam.name})}__POA.${tmpltHelper.getBasename(${serviceClassParam.name})}):
    """
    @class ${tmpltHelper.getBasename(${serviceClassParam.name})}_i
    Example class implementing IDL interface ${tmpltHelper.convFormat(${serviceClassParam.name})}
    """

    def __init__(self):
        """
        @brief standard constructor
        Initialise member variables here
        """
        pass

#foreach($serviceMethodParam in ${serviceClassParam.methods})
    # ${pyConv.convCORBA2PythonArg(${serviceMethodParam.type})} ${serviceMethodParam.name}(#foreach($serviceArgumentParam in ${serviceMethodParam.arguments})#if($velocityCount > 1), #end${serviceArgumentParam.direction} ${pyConv.convCORBA2PythonArg(${serviceArgumentParam.type})} ${serviceArgumentParam.name}#end)
    def ${serviceMethodParam.name}(self${pyConv.selectInParamName(${serviceMethodParam},${serviceClassParam})}):
        raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
        # *** Implement me
        # Must return:${pyConv.selectOutParamName(${serviceMethodParam},${serviceClassParam})}

#end

#end
if __name__ == "__main__":
    import sys
    
    # Initialise the ORB
    orb = CORBA.ORB_init(sys.argv)
    
    # As an example, we activate an object in the Root POA
    poa = orb.resolve_initial_references("RootPOA")

    # Create an instance of a servant class
    servant = ${tmpltHelper.getBasename(${idlFileParam.serviceClassParams.get(0).name})}_i()

    # Activate it in the Root POA
    poa.activate_object(servant)

    # Get the object reference to the object
    objref = servant._this()
    
    # Print a stringified IOR for it
    print(orb.object_to_string(objref))

    # Activate the Root POA's manager
    poa._get_the_POAManager().activate()

    # Run the ORB, blocking this thread
    orb.run()

